package com.soft.javase.ch12.test.recursion;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/14
 * 1.猴子吃桃子问题，第一天吃了一半多一个，第二天再吃一半多一个，第10天剩余1个，请问第一天摘了多少个桃子？
 */
public class MonkeyPeach {
    public static void main(String[] args) {
        int day = 10;
        int remaining = 1;
        int total = Peaches(day, remaining);
        System.out.println("第一天摘的桃子数量是: " + total);
    }

    public static int Peaches(int day, int remaining) {
        if (day == 1) {
            return remaining;
        } else {
            return (Peaches(day - 1, remaining) + 1) * 2;
        }
    }
}
